import request, { type ListResponse, type ListQuery } from "@/utils/request";

const BASE_URL = "/api/internal/webHook/task";

export const TaskAPI = {
  getTaskList: (params: ListQuery) => {
    return request.get<any, ListResponse<TaskType>>(`${BASE_URL}/`, {
      params,
    });
  },
  getTaskDetail: (id: number) => {
    return request.get<any, TaskType>(`${BASE_URL}/${id}/`);
  },
  updateTask: (data: Partial<TaskType>) => {
    return request.put(`${BASE_URL}/${data.id}/`, data);
  },
  deleteTask: (id: number) => {
    return request.delete(`${BASE_URL}/${id}/`);
  },
};

export type TaskListQuery = {} & ListQuery;

export type TaskType = {
  id: string; //记录 ID
  name: string; //记录名称
  target_url: string; //记录目标 URL
  payload: string; //记录负载
  created_at: string; //创建时间
  updated_at: string; //更新时间
  status: string; //记录状态
  curr_execute_count: number; //当前执行次数
  max_retry_count: number; //最大重试次数
  next_execute_time: null; //下次执行时间
  last_execute_time: null; //上次执行时间
  app: number; //应用标识
};

export default TaskAPI;
